from redis import StrictRedis
import logging


class Config(object):
    """工程配置信息"""
    DEBUG = True

    # 数据库的配置信息
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/NO2"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    # os包中urandom(48) 再导入base64 base64.b64encode(os.urandom(48))
    SECRET_KEY = "2lwYuEThWssCYGBRTv/6jKwDJNN+8Nitl1Hl2c4taW6Pj9MwZVFC3vDXXbW1mKoB"

    # redis配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # flask_session的配置信息
    # 之所以指定session保存到redis中是因为redis可以持久化保存信息
    SESSION_TYPE = "redis"
    # 让cookie中的session_id被加密
    SESSION_USE_SIGNER = True
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    PERMANENT_SESSION_LIFETIME = 86400


class DevelopmentConfig(Config):
    """开发模式下的配置"""
    DEBUG = True
    LOG_LEVEL = logging.DEBUG


class ProductionConfig(Config):
    """生产模式下的配置"""
    LOG_LEVEL = logging.ERROR

config_dict = {
    "development":DevelopmentConfig,
    "production":ProductionConfig
}
